package com.wzapp.sitposture.authentication.interceptor;

import com.wzapp.sitposture.common.base.SpringContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthenticationInterceptor implements HandlerInterceptor {

	protected static final Logger log = LoggerFactory.getLogger(AuthenticationInterceptor.class);

    Environment environment = SpringContextHolder.getBean("environment");

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

	    // 解决微信支付H5支付问题
        if ("/eShop/orders".equals(request.getServletPath())) {
            response.addHeader("Referer", environment.getProperty("ql.domain"));
        }

//modify ql 0921 去除验证，channel含义发生改变，用signAppId区分app
/*        HeaderParam headerParam = HeaderUtil.getHeaderParam(request);
        if (!"/setup/channels".equals(request.getServletPath())
				&& !"/notify/servernotify_ali".equals(request.getServletPath())
				&& !request.getServletPath().startsWith("/category/frontCategories")
				&& !"/eShop/orderPays".equals(request.getServletPath())
				&& !"/notify/servernotify_wx".equals(request.getServletPath())
				&& !"/notify/servernotify_apple".equals(request.getServletPath())
				&& !"/notify/videoupload_qn".equals(request.getServletPath())
				&& !"/notify/alipay_wap".equals(request.getServletPath())
				&& !"/notify/alipay_pc".equals(request.getServletPath())
				&& !"/notify/wx_wap".equals(request.getServletPath())
				&& !"/orders/webhook".equals(request.getServletPath())
				&& !"/wexin/share/varify".equals(request.getServletPath())
				&& !"/error".equals(request.getServletPath())
				&& !"/eShop/orderPays/ali".equals(request.getServletPath())){
			List<String> channels = headerParam.getChannel();
			if (ToolUtil.isEmpty(channels) || ToolUtil.isBlank(channels)) {
				throw new CustomizedException("public.param.channel.blank");
			}
		}*/

		return true;
	}

}
